package com.neuralnoise.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class HashingUtils {

	private HashingUtils() { }
	
	public static final String DEFAULT_HASHING_ALGORITHM = "SHA";
	
	public static String calculateHash(String input) throws NoSuchAlgorithmException {
		return calculateHash(input, DEFAULT_HASHING_ALGORITHM);
	}
	
	public static String calculateHash(String input, String algorithm) throws NoSuchAlgorithmException {
		MessageDigest md = MessageDigest.getInstance(algorithm);
		md.update(input.getBytes());
		byte messageDigest[] = md.digest();
		StringBuffer hexString = new StringBuffer();
		for (int i = 0; i < messageDigest.length; ++i) {
			hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
		}
		String ret = hexString.toString();
		return ret;
	}

	
}
